package com.hzit.controller;

import com.hzit.dto.StudentDTO;
import com.hzit.entity.PageResult;
import com.hzit.entity.R;
import com.hzit.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RestController
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private IStudentService studentService;

	//1. 查询所有学生
	@GetMapping("/list")
	public R list(){
		List<StudentDTO> dtoList = studentService.findAll();
		return R.ok(dtoList);
	}
	//2. 分页查询
	@GetMapping("/findPage")
	public R findPage(int page,int pageSize){
		PageResult<StudentDTO> pr = studentService.findPage(page,pageSize);
		return R.ok(pr);
	}
	//3. 条件查询带分页
	@PostMapping("/search")
	public R search(int page,int pageSize,@RequestBody StudentDTO dto){
		PageResult<StudentDTO> pr = studentService.search(page,pageSize,dto);
		return R.ok(pr);
	}
	//4. 添加学生
	@PostMapping("/add")
	public R add(@RequestBody StudentDTO dto){
		studentService.insert(dto);
		return R.ok(null,"添加学生成功！");
	}
	//5. 修改学生
	@PostMapping("/update")
	public R update(@RequestBody StudentDTO dto){
		studentService.update(dto);
		return R.ok(null,"修改学生成功！");
	}
	//6. 根据sid删除学生
	@GetMapping("/delete")
	public R delete(int sid){
		studentService.delete(sid);
		return R.ok(null,"删除学生成功！");
	}
}
